Preserve heredoc bodies for shell interpreters in deny checks#5
Merged
jim80net merged 1 commit intofix/strip-heredocs-before-matchingfrom Mar 7, 2026
Conversation
StripHeredocs now preserves heredoc bodies when the heredoc is fed as stdin to a shell interpreter (bash, sh, python, ruby, perl, node, etc.). Previously, all heredoc bodies were stripped before deny rule matching, which allowed bypassing deny rules via e.g. `bash <<'EOF'\nrm -rf /\nEOF`. Non-interpreter heredocs (cat, git commit messages, PR descriptions) are still stripped as before to avoid false positives on data content. https://claude.ai/code/session_017iMvRYni3dU8UACw1Jok9c
jim80net
added a commit
that referenced
this pull request
Mar 8, 2026
Preserve heredoc bodies for shell interpreters in deny checks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Modified the
StripHeredocsfunction to preserve heredoc bodies when they are fed as stdin to shell interpreters (bash, sh, python, etc.), while continuing to strip heredoc bodies for other commands likecat. This ensures that deny rules can properly inspect executable code passed to interpreters.Key Changes
shellHeredocReregex pattern to detect when heredocs are piped to shell interpreters (bash, sh, dash, zsh, ksh, fish, python, ruby, perl, node, php)StripHeredocsto conditionally preserve heredoc bodies based on whether they're being fed to a shell interpreterkeepBodyflag to track whether the current heredoc body should be preserved or strippedcatcommand are still strippedImplementation Details
The solution distinguishes between two types of heredocs:
cat <<EOF) - bodies are stripped since they contain data, not executable codebash <<EOF) - bodies are preserved since they contain executable code that deny rules must inspectThe
shellHeredocRepattern matches heredoc syntax immediately following shell interpreter commands, accounting for command chaining with;,&, and|operators.https://claude.ai/code/session_017iMvRYni3dU8UACw1Jok9c